﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using System.Diagnostics;

namespace ConsoleApplication1
{

    public class Program
    {
        private static int NUMBER_OF_COMPANIES = 5;
        private static int NUMBER_OF_EMPLOYEES = 50;
        private static int EMPLOYEES_PER_COMPANY = 10;
        private static int ROLES_PER_EMPLOYEE = 2;
        private static double DEFAULT_BASE_WAGE = 10;
        private static int NUMBER_OF_PROJECTS = 5;
        private static int NUMBER_OF_TASKS = 5;
        private static int NUMBER_OF_MANUFACTURINGTASKS = 3;
        private static int NUMBER_OF_MACHINES = 3;

        static void Main(string[] args)
        {
            List<Role> roles = new List<Role>() 
            {   new Role("Marketing",new MarketingBonus()),
                new Role("Development",new DevelopmentBonus()),
                new Role("Design",new DesignBonus())
            };

            var changeCompany = new ChangeCompany();
            var changeEmployee = new ChangeEmployee();
            var changeProject=new ProjectChange();
            var changeTask=new TaskChange();
            var changeMachine = new ChangeMachine();
            var changeManufacturingTask = new ChangeManufacturingTask();

            for (var c = 0; c < NUMBER_OF_COMPANIES; c++)
            {

                var comp = new Company("COMP" + c, "Description of company" + c);
                changeCompany.AddCompany(comp);


                //changeCompany.CreateCompany("COMP" + c, "Description of company" + c);
            }
            //Console.WriteLine("Companies: " + changeCompany.GetCompanies().Count());



            for (var i = 0; i < NUMBER_OF_EMPLOYEES; i++)
            {
                List<Role> employeeRoles = new List<Role>();

                var emp = new Employee("Employee" + i, "CODEMP" + i, DateTime.Now.AddYears(-i), DEFAULT_BASE_WAGE);
                changeEmployee.AddEmployee(emp);

                //changeEmployee.CreateEmployee("Employee" + i, "CODEMP" + i, DateTime.Now.AddDays(-i), 10);

                //var emp = changeEmployee.CreateEmployee("Employee" + i, "CODEMP" + i, DateTime.Now.AddDays(-i), 10);

                Random randomRoles = new Random();
                int random = randomRoles.Next(0, ROLES_PER_EMPLOYEE);

                employeeRoles.Add(roles[random]);

                //adauga employee-ului cate un rol la random

                foreach (Role role in employeeRoles)
                {
                    emp.AddRoleToEmployee(role);
                }
            }
            //Console.WriteLine("Employees: " + changeEmployee.GetEmployees().Count());

            var _companies = changeCompany.GetCompanies();
            var _employees = changeEmployee.GetEmployees();

            List<Company> companyList = _companies == null ? null : _companies.ToList();
            List<Employee> employeeList = _employees == null ? null : _employees.ToList();
            int count = EMPLOYEES_PER_COMPANY;

            // adauga primii 10 employees la prima companie, urmatorii 10 la a doua, etc
            for (int iterationNr = 0; iterationNr < companyList.Count; iterationNr++)
            {
                
                for (int c = (count * iterationNr); c < count + (count * iterationNr); c++)
                {
                    companyList[iterationNr].AddEmployeeToCompany(employeeList[c]);

                }
            }

            //foreach (Employee emp in _employees)
            //{
            //    Console.WriteLine("Wage of employee " + emp.EmployeeCode + ": " + emp.Wage);

            //}

            //generate 5 projects
            for (var c = 0; c < NUMBER_OF_PROJECTS; c++)
            {

                var proj = new Project("PROJ" + c);
                changeProject.AddProject(proj);
            }

            //assign projects to the companies

            var _projects = changeProject.GetProjects();
            List<Project> projectList = _projects == null ? null : _projects.ToList();

            for (var i = 0; i < companyList.Count; i++)
            {
                companyList[i].AddProjectToCompany(projectList[i]);
            }

            //generate tasks
             for (var t = 0; t < NUMBER_OF_TASKS; t++)
                {
                    var task = new Task("TASK" + t, 100, employeeList[t]);
                    changeTask.AddTask(task);
                }

            //assign tasks to projects

             var _tasks = changeTask.GetTasks();
             List<ITask> taskList = _tasks == null ? null : _tasks.ToList();

            for (var i = 0; i < projectList.Count; i++)
            {
                projectList[i].AddTaskToProject(taskList[i]);
            }

            //generate 3 machines
            for (var m = 0; m < NUMBER_OF_MACHINES; m++)
            {
                var machine = new Machine("MACHINE_CODE" + m, "MACHINE" + m, 50);
                changeMachine.AddMachine(machine);
            }

            //generate 5 manufacturing tasks 
            var _machine = changeMachine.GetMachines();
            List<Machine> machineList = _machine == null ? null : _machine.ToList();

            for (var t = 0; t < NUMBER_OF_MANUFACTURINGTASKS; t++)
            {
                var manufacturingTask = new ManufacturingTask("MAN_TASK" + t, 100, employeeList[t], machineList[t]);
                changeManufacturingTask.AddManufacturingTask(manufacturingTask);
            }

            
            //assign  manufacturing tasks to the first 3 projects
            var _manufacturingTask = changeManufacturingTask.GetManufacturingTasks(); ;
            List<ITask> manufacturingTasksList = _manufacturingTask == null ? null : _manufacturingTask.ToList();

            for (var i = 0; i < NUMBER_OF_MANUFACTURINGTASKS; i++)
            {
                projectList[i].AddTaskToProject(manufacturingTasksList[i]);
            }
            
           
            //foreach (var proj in _projects)
            //{
            //    Console.WriteLine("estimated cost for proj " + proj.ProjectCode + "is: " + proj.EstimatedCost);
            //}

            //TODO: add employee to a company
            
            //Console.WriteLine("Employee name: ");
            //string employeeName = Console.ReadLine();
            //Console.WriteLine("Employee code:");
            //string employeeCode = Console.ReadLine();
            //Console.WriteLine("Employee hire date: ");
            //DateTime hireDate =DateTime.Parse( Console.ReadLine());
            //Console.WriteLine("Base wage: ");
            //double baseWage =double.Parse( Console.ReadLine());

            //Console.WriteLine("company code: ");
            //string companyCode = Console.ReadLine();

            //Employee employee = new Employee(employeeName, employeeCode, hireDate, baseWage);

            //foreach (Company comp in companyList)
            //{
            //    if (comp.CompanyCode == companyCode)
            //    {
            //        comp.AddEmployeeToCompany(employee);
            //        break;
            //    }
            //}


            //TODO: remove employee from a company
            //Console.WriteLine("company code: ");
            //var companyCode = Console.ReadLine();
            //Console.WriteLine("Employee code");
            //var employeeCode = Console.ReadLine();

            //foreach (Company comp in companyList)
            //{
            //    if (comp.CompanyCode == companyCode)
            //    {
            //        Employee emp = comp.GetEmployeeByCode(employeeCode);
            //        comp.RemoveEmployeeFromCompany(emp);
            //        break;
            //    }
            //}

            //TODO: change the Company code
            //TODO: change the Company description
            //TODO: delete a company

            //TODO: add role to an employee
            Console.WriteLine("employee code: ");
            var employeecode = Console.ReadLine();

            foreach (Employee emp in employeeList)
            {
                if (emp.EmployeeCode == employeecode)
                {
                    emp.AddRoleToEmployee(roles[2]);
                    Console.WriteLine("Employee with code " + emp.EmployeeCode + " has wage: " + emp.Wage);
                    break;
                }
            }
            //TODO: remove role from an employee
            //TODO: delete an employee
            //TODO: change the employee code/ name
            //TODO: add tasks to a project
         }
        }
    }


